<link rel="stylesheet" type="text/css" href="assets/bootstrap-datepicker/css/datepicker.css" />
<aside class="lg-side">
  <div class="panel-heading tab-bg-dark-navy-blue okr-tab-head tab-right "></div>
  <div class="inbox-body mi-h8">

    <div class="row">
      <div class="col-lg-12">
        <div class="alert alert-block alert-warning fade in">
          <button data-dismiss="alert" class="close close-sm" type="button">
            <i class="icon-remove"></i>
          </button>
          <strong>注意事项：</strong>
          项目经理填写项目进展时，请依据其他重要角色的进展情况给出项目整体进展说明，不能局限于个人单方面的进展；若无进展，请填写无进展及其原因！
          例如（对于销售项目，项目经理要综合销售、技术支持、交付等方面进展给出整体说明）。
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-lg-12">
        <div class="alert alert-block alert-danger fade in">
          <button data-dismiss="alert" class="close close-sm" type="button">
            <i class="icon-remove"></i>
          </button>
          <strong>友情提示：</strong><br>
          1、填写进展时，开始时间要以上周周六开始，结束时间填写周五；<br>
          2、如果输入内容时候想排版实现换行，可在需要换行的地方增加&lt;/br&gt;，即可实现排版换行。
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-lg-12">
        <form>
          <section class="panel">
            <header class="panel-heading">
              项目整体进展信息
            </header>
            <div class="panel-body">
              <div class="panel-body">
                <div class="form-group customerForm">
                  <label class="col-sm-2 control-label">填写周期*</label>
                  <div class="col-sm-10">
                    <div class="row">
                      <div class="col-lg-6 n-p0">
                        <input id="datetime" disabled name="startTime" type="text" value="" class="form-control"
                          placeholder="开始时间" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                      </div>
                      <div class="col-lg-6 n-p0">
                        <input id="datetime-1" name="endTime" type="text" value="" style="background-color: #fafafa"
                          readonly autocomplete="off" class="form-control" placeholder="结束时间"
                          onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">项目整体进展*</label>
                <div class="col-sm-10">
                  <textarea class="form-control" name="content" id="content" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"
                    maxlength="500" placeholder="字数限制(500字以内)"></textarea>
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">下一步计划*</label>
                <div class="col-sm-10">
                  <textarea class="form-control" name="nextStep" id="nextStep" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"
                    maxlength="500" placeholder="字数限制(500字以内)"></textarea>
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">本周客户投诉</label>
                <div class="col-sm-10">
                  <textarea class="form-control" name="nowCustomerComplain" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"
                    placeholder="字数限制(120字以内)" maxlength="120"></textarea>
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">本周客户需求</label>
                <div class="col-sm-10">
                  <textarea class="form-control" name="nowCustomerRequest" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"
                    placeholder="字数限制(120字以内)" maxlength="120"></textarea>
                </div>
              </div>
              <p class="default-buttons">
                <a href="javascript:void(0);" class="button-back btn btn-info" onclick="toBack()">返回</a>
                <a href="javascript:void(0);" class="button-next  btn btn-info submit">提交</a>
              </p>
            </div>
          </section>
        </form>
      </div>
    </div>
  </div>
</aside>
<script type="text/javascript" src="assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script>
  // $('#datetime').datepicker({
  //   format: 'yyyy-mm-dd'
  // });
  $('#datetime-1').datepicker({
    format: 'yyyy-mm-dd'
  }).on('changeDate', function (e) {
    var date = new Date($("#datetime-1").val().replace(/-/, "/").replace("-", "/"));
    //计算相差多少天
    var d = new Date();
    var time = d.getTime() - date.getTime();
    var days = parseInt(time / (1000 * 60 * 60 * 24));
    if (days > 30) {
      layer.msg("结束日期不能超过当前日期30天");
      $("#datetime-1").val("");
      $("#datetime").val("");
      return;
    }

    var weekDay = [7, 1, 2, 3, 4, 5, 6];
    if (weekDay[date.getDay()] != 5) {
      layer.msg("结束日期必须为星期五");
      $("#datetime-1").val("");
      $("#datetime").val("");
      return;
    } else {
      //开始日期为结束日期的前
      var now = new Date(date.getTime() - 86400000 * 6);
      var year = now.getFullYear(),
        month = (now.getMonth() + 1).toString(),
        day = now.getDate().toString();
      if (month.length == 1) {
        month = '0' + month;
      }
      if (day.length == 1) {
        day = '0' + day;
      }
      var datetime = (year + '-' + month + '-' + day);
      $("#datetime").val(datetime);
    }
  });

  function toBack() {
    toLoadHtml(4, 2);
  }



  $(".submit").on('click', function () {
    var content = $("#content").val();
    if (content == "" || content == null || content == undefined) {
      layer.msg("整体进展不能为空!");
      return;
    }

    var nextStep = $("#nextStep").val();
    if (nextStep == "" || nextStep == null || nextStep == undefined) {
      layer.msg("下一步计划不能为空!");
      return;
    }

    var datetime = $("#datetime").val();
    var endTime = $("#datetime-1").val();

    if (datetime == "" || datetime == null || datetime == undefined) {
      layer.msg("开始日期不能为空!");
      return;
    }

    if (endTime == "" || endTime == undefined || endTime == null) {
      layer.msg("结束日期不能为空!");
      return;
    }
    var arr = $("form").serializeArray();
    var data = {};
    for (var i = 0; i < arr.length; i++) {
      data[arr[i].name] = arr[i].value;
    };
    data.proId = proId;
    data.startTime = datetime;
    $certusUtils.ajax('getRpCount', {
      "endTime": endTime,
      "proId": proId
    }, function (response) {
      if (response.data >= 1) {
        layer.msg("项目进展不能重复提交", {
          "time": 1000
        });
      } else {
        $certusUtils.ajax("toAddNewReport", {
          "param": JSON.stringify(data)
        }, function () {
          layer.msg("添加成功", {
            "time": 1000
          });
          toLoadHtml(4, 2);
        });
      }
    });
  });
  //n为你要传入的参数，当前为0，前一天为-1，后一天为1
  function getBeforeDate(n) {
    var date = new Date();
    var year, month, day;
    date.setDate(date.getDate() + n);
    year = date.getFullYear();
    month = date.getMonth() + 1;
    day = date.getDate();
    s = year + '-' + (month < 10 ? ('0' + month) : month) + '-' + (day < 10 ? ('0' + day) : day);
    return s;
  }
</script>